/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.packet.server;

import java.io.IOException;

import lineage.core.Opcodes;
import lineage.model.instance.L1PcInstance;
import lineage.packet.L1AbstractPacketServer;

/**
 * 物件封包：自身.
 * <p>
 * objid如果为0 则对象的头顶会显示王冠
 * 
 * @version 2014年3月16日下午3:19:15
 * @author jrwz
 */
public final class S_CharPackOwn extends L1AbstractPacketServer {
    private byte[] _byte = null;

    /**
     * 物件封包：自身.
     * 
     * @param pc
     *            - 要更新的对象
     */
    public S_CharPackOwn(final L1PcInstance pc) {
        writeC(Opcodes.S_OPCODE_CHAR_PACK);
        writeH(pc.getX()); // x坐标
        writeH(pc.getY()); // y坐标
        writeD(pc.getId()); // OBJID
        writeH(pc.getClassId()); // 外形(外观图像)
        writeC(pc.getAction()); // 初始化状态(动作)
        writeC(pc.getHeading()); // 面向
        writeC(pc.getLight()); // 自身的亮度(照明)范围
        writeC(pc.getSpeed()); // 移动速度：(0.正常 1.加速 2.缓速)
        writeD((int) pc.getExp()); // 经验值
        writeH(pc.getLawful()); // 正义值
        writeS(pc.getName()); // 名称
        writeS(pc.getTitle()); // 封号
        writeC(pc.getStatus()); // 状态(0:NPC,道具、1:中毒 、2:隐身、4:PC、8:诅咒、16:勇水、128:幽灵状态)
        writeD(pc.getClanId()); // 血盟编号
        writeS(pc.getClanName()); // 血盟名称
        writeS(pc.getMasterName()); // 主人名称
        writeC(pc.getClanRank());// 血盟阶级
        writeC(0xFF); // HP血条显示
        writeC(0x08); // 3段加速
        writeC(0x00); // 等级(PC = 0, Mon = Lv)
        writeC(0x00);
        writeC(0xFF);
        writeC(0xFF);
    }

    @Override
    public byte[] getContent() throws IOException {
        if (this._byte == null) {
            this._byte = this.getBytes();
        }
        return this._byte;
    }
}
